#include "StdAfx.h"
#include "CircuitBusEntry.h"


CCircuitBusEntry::CCircuitBusEntry(void)
{
	m_dblStartPosX = 0.0;
	m_dblStartPosY = 0.0;
	m_dblEndPosX = 0.0;
	m_dblEndPosY = 0.0;
	m_dblLineWidth = 0.0;
	m_dblColor[0] = 0.0;
	m_dblColor[1] = 0.0;
	m_dblColor[2] = 0.0;
	m_bSelect = false;
}

CCircuitBusEntry::CCircuitBusEntry(const CCircuitBusEntry *pEntityObj)
	: CCircuitUnit(pEntityObj)
{
	m_dblStartPosX = pEntityObj->GetStartPosX();
	m_dblStartPosY = pEntityObj->GetStartPosY();
	m_dblEndPosX = pEntityObj->GetEndPosX();
	m_dblEndPosY = pEntityObj->GetEndPosY();
	m_dblLineWidth = pEntityObj->GetLineWidth();
	m_dblColor[0] = pEntityObj->GetColorR();
	m_dblColor[1] = pEntityObj->GetColorG();
	m_dblColor[2] = pEntityObj->GetColorB();
	m_bSelect = pEntityObj->IsSelect();
}

CCircuitBusEntry::CCircuitBusEntry(CICircuit *pParentEnt)
	: CCircuitUnit(pParentEnt)
{
	m_dblStartPosX = 0.0;
	m_dblStartPosY = 0.0;
	m_dblEndPosX = 0.0;
	m_dblEndPosY = 0.0;
	m_dblLineWidth = 0.0;
	m_dblColor[0] = 0.0;
	m_dblColor[1] = 0.0;
	m_dblColor[2] = 0.0;
	m_bSelect = false;
}

CCircuitBusEntry::~CCircuitBusEntry(void)
{
	Clear();
}

void CCircuitBusEntry::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		ar << m_dblStartPosX;
		ar << m_dblStartPosY;
		ar << m_dblEndPosX;
		ar << m_dblEndPosY;
		ar << m_dblLineWidth;
		ar << m_dblColor[0];
		ar << m_dblColor[1];
		ar << m_dblColor[2];
		ar << m_bSelect;
	}
	else
	{
		ar >> m_dblStartPosX;
		ar >> m_dblStartPosY;
		ar >> m_dblEndPosX;
		ar >> m_dblEndPosY;
		ar >> m_dblLineWidth;
		ar >> m_dblColor[0];
		ar >> m_dblColor[1];
		ar >> m_dblColor[2];
		ar >> m_bSelect;
	}

	CCircuitUnit::Serialize(ar);
}

CObj *CCircuitBusEntry::Clone() const
{
	return new CCircuitBusEntry(this);
}

void CCircuitBusEntry::Transform(const CMatrix transf)
{

}

bool CCircuitBusEntry::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	dblLeft = m_minX ;
	dblBottom = m_minY;
	dblRight = m_maxX;
	dblTop = m_maxY;
	return true;
}

void CCircuitBusEntry::Clear()
{

}

void CCircuitBusEntry::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CCircuitBusEntry::DeleteDisplayObj(long lLayerId)
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}

CDisplayObj * CCircuitBusEntry::CreateDisplayObj(long lLayerId)
{
	CCircuitBusEntryDisObj *pBusEntDis = new CCircuitBusEntryDisObj(this);
	pBusEntDis->SetLayerId(lLayerId);
	return pBusEntDis;
}

void CCircuitBusEntry::CalcBox()
{
	m_minX = min(m_dblStartPosX, m_dblEndPosX);
	m_minY = min(m_dblStartPosY, m_dblEndPosY);
	m_maxX = max(m_dblStartPosX, m_dblEndPosX);
	m_maxY = max(m_dblStartPosY, m_dblEndPosY);
}

eCircuitUnitEntType CCircuitBusEntry::GetUnitType() const
{
	return CIRCUIT_BUSENTRY;
}

double CCircuitBusEntry::GetStartPosX() const
{
	return m_dblStartPosX;
}

double CCircuitBusEntry::GetStartPosY() const
{
	return m_dblStartPosY;
}

double CCircuitBusEntry::GetEndPosX() const
{
	return m_dblEndPosX;
}

double CCircuitBusEntry::GetEndPosY() const
{
	return m_dblEndPosY;
}

double CCircuitBusEntry::GetLineWidth() const
{
	return m_dblLineWidth;
}

double CCircuitBusEntry::GetColorR() const
{
	return m_dblColor[0];
}

double CCircuitBusEntry::GetColorG() const
{
	return m_dblColor[1];
}

double CCircuitBusEntry::GetColorB() const
{
	return m_dblColor[2];
}

bool CCircuitBusEntry::IsSelect() const
{
	return m_bSelect;
}

void CCircuitBusEntry::SetStartPosX(double posX) 
{
	m_dblStartPosX = posX;
}

void CCircuitBusEntry::SetStartPosY(double posY)
{
	m_dblStartPosY = posY;
}

void CCircuitBusEntry::SetEndPosX(double posX)
{
	m_dblEndPosX = posX;
}

void CCircuitBusEntry::SetEndPosY(double posY)
{
	m_dblEndPosY = posY;
}

void CCircuitBusEntry::SetLineWidth(double dblWidth) 
{
	m_dblLineWidth = dblWidth;
}

void CCircuitBusEntry::SetColorR(double colR)
{
	m_dblColor[0] = colR;
}

void CCircuitBusEntry::SetColorG(double colG)
{
	m_dblColor[1] = colG;
}

void CCircuitBusEntry::SetColorB(double colB)
{
	m_dblColor[2] = colB;
}

void CCircuitBusEntry::SetSelect(bool bFlag)
{
	m_bSelect = bFlag;
}

